<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="View.*" %>
<%@ page import="java.util.ArrayList" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ToWa Webshop Packingpage</title>
</head>
<body>
<%
UserView requestingUser = (UserView) request.getSession().getAttribute("user");

if (requestingUser == null) {
	RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
	dispatcher.forward(request, response);
}
if (requestingUser.getRank() != 2 && requestingUser.getRank() != 0) {
	RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
	dispatcher.forward(request, response);
}

ArrayList<OrderView> orders = Controller.getAllUnpackedOrders();
%>
<div id="container">
		<div id="content">
			
				<tr><th><u>Unpacked orders</u></th></tr>
									<%
					for (int i = 0; i < orders.size(); i++) {
						if (orders.get(i).getStatus() == 0) {
					%>
						<form action="item" method="post">
							<table>
							<tr>
							<td><b>Order Id:</b> <%=orders.get(i).getOrderId()%></td>
							</tr>
							<tr>
								<td><u>Item:</u></td><td><u>Amount:</u></td>
							</tr>
							<%
							ArrayList<OrderItemView> itemsInOrder = orders.get(i).getItems();
							for (int j = 0; j < itemsInOrder.size(); j++) {
							%>
								<tr>
									<td><%=itemsInOrder.get(j).getItem().getName()%></td><td><%=itemsInOrder.get(j).getAmount()%></td>
								</tr>
							<%
							}
						}
						%>
						<tr><td>&nbsp;</td></tr>
						</table>
						<input type="submit" value="Pack" />
						<input type="hidden" name="hidden" value="orderId_<%=orders.get(i).getOrderId()%>" />
						</form>
					<%
					}
					%>
		</div>
	</div>
</body>
</html>